# -*- coding:utf-8 -*-
# __author__ : "张百科"
# Date: 2021/1/25 21:22
# File: advise.py
# IDE: PyCharm

from rest_framework import serializers
from models.advise import Advise
from models.wxuser import WxUser
class AdviseSerializer(serializers.ModelSerializer):
    wx_user_id = serializers.IntegerField(required=True)
    #wx_user_name=serializers.SerializerMethodField(read_only=True)
    category=serializers.CharField(label='意见类型',max_length=50,help_text='意见类型')
    category_display=serializers.SerializerMethodField(read_only=True)
    content=serializers.CharField(label='意见内容', max_length=1000, help_text='意见内容',required=True)
    create_time = serializers.DateTimeField(label='提交时间',help_text='提交时间',read_only=True)
    reply=serializers.CharField(label='回复内容',help_text='回复内容',required=False,max_length=1000)
    reply_time = serializers.DateTimeField(label='回复时间', help_text='回复时间', read_only=True)
    is_satisfied=serializers.IntegerField(label='是否满意', help_text='是否满意',read_only=True)
    is_public = serializers.IntegerField(label='是否公开', help_text='是否公开',read_only=True)
    read_count = serializers.IntegerField(label='阅读量', help_text='阅读量', read_only=True)

    # def get_wx_user_name(self,obj):
    #     return WxUser.objects.get(pk=obj.id)

    def get_category_display(self,obj):
        return  obj.get_category_display()

    class Meta:
        model = Advise
        exclude = ('is_delete',)